﻿using VCDIFF.Differencing.DiffAlgorithm;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections;
using VCDIFF.Commands;
using System.Collections.Generic;
using System.Text;
using VCDIFF.Rebuild;
using System.IO;

namespace VCDIFF.Tests
{
    
    
    /// <summary>
    ///This is a test class for ExecuteDiffTest and is intended
    ///to contain all ExecuteDiffTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ExecuteDiffTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for WriteVCDIFF
        ///</summary>
        [TestMethod()]
        [DeploymentItem("VCDIFF.Differencing.exe")]
        public void WriteVCDIFFTest()
        {/*
            IList<Command> commandsList = null; // TODO: Initialize to an appropriate value
            long sourceLength = 0; // TODO: Initialize to an appropriate value
            ExecuteDiff_Accessor.WriteVCDIFF(commandsList, sourceLength);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");*/
        }

        /// <summary>
        ///A test for ToByteArray
        ///</summary>
        [TestMethod()]
        [DeploymentItem("VCDIFF.Differencing.exe")]
        public void ToByteArrayTest1()
        {/*
            string s = string.Empty; // TODO: Initialize to an appropriate value
            byte[] expected = null; // TODO: Initialize to an appropriate value
            byte[] actual;
            actual = ExecuteDiff_Accessor.ToByteArray(s);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");*/
        }

        /// <summary>
        ///A test for ToByteArray
        ///</summary>
        [TestMethod()]
        [DeploymentItem("VCDIFF.Differencing.exe")]
        public void ToByteArrayTest()
        {/*
            IList<Command> commandsList = null; // TODO: Initialize to an appropriate value
            byte[] expected = null; // TODO: Initialize to an appropriate value
            byte[] actual;
            actual = ExecuteDiff_Accessor.ToByteArray(commandsList);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");*/
        }

        /// <summary>
        ///A test for Execute
        ///</summary>
        [TestMethod()]
        public void ExecuteTest()
        {
            string filePath = @"original";

            StringBuilder originalText = new StringBuilder();
            originalText.Append("The standard Lorem Ipsum passage, used since the 1500s\n\n");
            originalText.Append("\"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\"\n\n");
            originalText.Append("Section 1.10.32 of \"de Finibus Bonorum et Malorum\", written by Cicero in 45 BC\n\n");
            originalText.Append("\"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?\"\n");

            File.WriteAllText(filePath, originalText.ToString());

            StringBuilder resultText = new StringBuilder();
            resultText.Append("The standard Lorem Ipsum passage, used since the 1500s\n\n");
            resultText.Append("\"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\"\n\n");
            resultText.Append("Section 1.10.32 of \"de Finibus Bonorum et Malorum\", written by Cicero in 45 BC\n\n");
            resultText.Append("\"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?\"\n\n");
            resultText.Append("The standard Lorem Ipsum passage, used since the 1500s\n\n");
            resultText.Append("\"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\"\n");
            resultText.Append("blabla\n\n");
            resultText.Append("Section 1.10.32 of \"de Finibus Bonorum et Malorum\", written by Cicero in 45 BC\n\n");
            resultText.Append("\"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?\"\n");

            File.WriteAllText(filePath + "_result", resultText.ToString());

            TextFileAlgorithm algorithm = new TextFileAlgorithm(DiffEngineLevel.SlowPerfect);
            VCDFile vcdFile = algorithm.CreateVCDIFF(filePath);
            VCDFile.Serialize(vcdFile, filePath);
            
            bool expected = true;
            bool actual = CheckSumMD5.verifyIntegrity(filePath + "_result", filePath + "_modified");
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ExecuteDiff Constructor
        ///</summary>
        [TestMethod()]
        public void ExecuteDiffConstructorTest()
        {/*
            ExecuteDiff target = new ExecuteDiff();
            Assert.Inconclusive("TODO: Implement code to verify target");*/
        }
    }
}
